#include <stdio.h>
#include <unistd.h>
#include <poll.h>

//非阻塞监控 0 号文件描述符

int main()
{
    struct pollfd pf;
    pf.fd = 0;
    pf.events = POLLIN;

    while(1)
    {
        int ret = poll(&pf, 1, 0); //0表示非阻塞
        if(ret < 0)
        {
            perror("poll");
            return 0;
        }
        else if(ret == 0)
        {
            printf("poll timeout\n");
            sleep(1);
            continue; //超时，继续监控
        }

        char buf[1024] = {0};
        read(0, buf, sizeof(buf) - 1);
        printf("buf is : %s\n", buf);
    }
    return 0;
}
